<p>When boxed type <code>java.lang.Boolean</code> is used as an expression it will throw <code>NullPointerException</code> if the value is
<code>null</code> as defined in <a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-5.html#jls-5.1.8">Java Language Specification §5.1.8
Unboxing Conversion</a>.</p>
<p>It is safer to avoid such conversion altogether and handle the <code>null</code> value explicitly.</p>
<h2>Noncompliant Code Example</h2>
<pre>
Boolean b = getBoolean();
if (b) {  // Noncompliant, it will throw NPE when b == null
  foo();
} else {
  bar();
}
</pre>
<h2>Compliant Solution</h2>
<pre>
Boolean b = getBoolean();
if (Boolean.TRUE.equals(b)) {
  foo();
} else {
  bar();  // will be invoked for both b == false and b == null
}
</pre>
<h2>See</h2>
<ul>
  <li> <a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-5.html#jls-5.1.8">Java Language Specification §5.1.8 Unboxing Conversion</a>
  </li>
</ul>

